import org.bytedeco.javacv.CanvasFrame;
import org.bytedeco.javacv.OpenCVFrameGrabber;

import javax.swing.*;

public class JavaCVCamera {

    /**
     * 第一个案例抓取摄像头，每隔50毫秒显示在窗口上
     * @param args
     * @throws Exception
     */
    public static void main(String args[]) throws Exception{

        OpenCVFrameGrabber grabber = new OpenCVFrameGrabber(0);
        grabber.start();

        CanvasFrame canvasFrame = new CanvasFrame("抓取摄像头");
        canvasFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        canvasFrame.setAlwaysOnTop(true);

        while(true){
            if(!canvasFrame.isDisplayable()){
                grabber.stop();
                System.exit(2);
            }

            canvasFrame.showImage(grabber.grab());
            Thread.sleep(50);
        }





    }




}
